<!DOCTYPE html>
<html>
#{include file="header.html"}#
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
  <div class="row">
    <div class="col-sm-12">
      <div class="ibox float-e-margins">
        <div class="ibox-title">
          <h5><i class="fa fa-home"></i> 商品品牌</h5>
          <div class="ibox-tools"> <a href="#{$smarty.const.ACT}#/goods/GoodsBrand/goods_brand_add/" >
            <button type="button" class="btn btn-xs btn-primary"><i class='fa fa-plus'></i> 添加</button>
            </a> <a href="?">
            <button type="button" class="btn btn-xs btn-danger"> <i class='fa fa-refresh'></i>刷新</button>
            </a> </div>
        </div>
        <div class="ibox-content">
          <table class="table table-hover sorttable 07fly-table">
            <thead>
              <tr>
                <th width="22"><input type="checkbox" group="ids" class="checkboxCtrl"></th>
                <th width="50">品牌名称</th>
                <th width="50">品牌图片</th>
                <th width="50">品牌首字母</th>
                <th width="20">是否推荐</th>
                <th width="50">排序</th>
                <th width="50">操作</th>
              </tr>
            </thead>
            <tbody>
            </tbody>
            <tfoot class="ibox-content">
              <tr>
                <td colspan="7" align="center"></td>
              </tr>
            </tfoot>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>
</body>
</html>
<script id="tableListTpl" type="text/html">
<% for(var i=0;i<list.length;i++) { %>
	<tr>
		<td><input name="ids" value="<%=list[i]['brand_id']%>" type="checkbox"></td>
		<td><%=list[i]['brand_name']%></td>
		<td>
			 <%if(list[i]['brand_pic'].length>0){%>
				<img src="<%=list[i]['brand_pic']%>" width="80" height="60">
			　<%}else{%> 
　　　　　　	<img src='/upload/images/defaultpic.png'>
	  		<%}%> 
		</td>
		<td><%=list[i]['brand_initial']%></td>
		<td>
	
      <div class="onoffswitch">
       		<input type="checkbox" class="onoffswitch-checkbox" data-brand-id="<%=list[i]['brand_id']%>"  id="brand_recommend_<%=list[i]['brand_id']%>"  <%if(list[i]['brand_recommend']==1){%> checked  <%}%>  >
	   		<label class="onoffswitch-label" for="brand_recommend_<%=list[i]['brand_id']%>"> 
	   			<span class="onoffswitch-inner"></span> 
				 <span class="onoffswitch-switch"></span> 
			 </label>
      </div>

		</td>
		<td>
			<input type="text" name="sort" value="<%=list[i]['sort']%>" class="form-control w50 brand_sort" onblur="brand_sort(this,<%=list[i]['brand_id']%>)" size="5">
		</td>
		<td><a href="#{$smarty.const.ACT}#/goods/GoodsBrand/goods_brand_modify/brand_id/<%=list[i]['brand_id']%>/">修改</a> 
			   <a href="#{$smarty.const.ACT}#/goods/GoodsBrand/goods_brand_del/brand_id/<%=list[i]['brand_id']%>/">删除</a>
		</td>
	</tr>
<% } %>
</script>
<!-- 自定义js --> 
<script src="#{$smarty.const.APP}#/View/template/js/content.js?v=1.0.0"></script> 
<script type="text/javascript">
var ajaxUrl='#{$smarty.const.ACT}#/goods/GoodsBrand/goods_brand_json/';
$(document).ready(function () {
	 turnPage(1);//页面加载时初始化分页
	
	$("body").on("click", ".onoffswitch-checkbox", function() {
		brand_id =$(this).attr("data-brand-id")
		ischecked=$(this).prop('checked');
		if(ischecked){
		   brand_recommend='1';
		}else{
			brand_recommend='0';
		}
		$.ajax({
			type: "POST",
			url: "#{$smarty.const.ACT}#/goods/GoodsBrand/goods_brand_modify_recommend/",
			data:{"brand_recommend":brand_recommend,"brand_id":brand_id},
			dataType:"json",
			success: function(data){
				if(data.rtnstatus=='success'){
					layer.msg('操作成功', {icon: 1});   
				}
				console.log(data.rtnstatus);
			}
		});
	});
	
});

function brand_sort(obj,brand_id){
	val=obj.value;
	$.ajax({
		type: "POST",
		url: "#{$smarty.const.ACT}#/goods/GoodsBrand/goods_brand_modify_sort/",
		data:{"sort":val,"brand_id":brand_id},
		dataType:"json",
		success: function(data){
			if(data.rtnstatus=='success'){
				layer.msg('操作成功', {icon: 1});   
			}
			console.log(data.rtnstatus);
		}
	});   
}
function brand_recommend(obj,brand_id){
	val=obj.value;
	$.ajax({
		type: "POST",
		url: "#{$smarty.const.ACT}#/goods/GoodsBrand/goods_brand_modify_sort/",
		data:{"sort":val,"brand_id":brand_id},
		dataType:"json",
		success: function(data){
			if(data.rtnstatus=='success'){
				layer.msg('操作成功', {icon: 1});   
			}
			console.log(data.rtnstatus);
		}
	});   
}
</script>